* Polity score 8 and above countries
clear all
use "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\Electoral Studies Submission\revision-data analysis\cses_imd.dta"

keep if IMD5051_1>=8 &  IMD5051_1!=99 
tab IMD1006_NAM
tab IMD1004

*drop two-party systems 
drop if IMD1006_NAM=="United States of America" | IMD1006_NAM=="Taiwan"

*14 elections dropped. having more than 100 percent vote total.
drop if IMD1004=="CHL_1999" | IMD1004=="CHL_2009" | IMD1004=="CZE_2002" | IMD1004=="DNK_2007" | IMD1004=="HUN_2002" | IMD1004=="MEX_2006" | IMD1004=="POL_2001" | IMD1004=="ROU_2004" | IMD1004=="ROU_2014" | IMD1004=="BRA_2010" | IMD1004=="JPN_2004" | IMD1004=="JPN_2007" | IMD1004=="JPN_2013" | IMD1004=="PHL_2016"


recode IMD5001_A-IMD5001_I (0=.) (70/.=.) // missing values lower house election vote shares
foreach var of varlist IMD5001_A-IMD5001_I {
replace `var'=.  if `var'<5
}
recode IMD3008_A-IMD3008_I (11/.=.) // missing values like-dislike scores

recode IMD5003_A-IMD5003_I (0=.) (70/.=.) // missing values upper house vote shares
foreach var of varlist IMD5003_A-IMD5003_I {
replace `var'=.  if `var'<5
}
recode IMD5005_A-IMD5005_I (0=.) (70/.=.) // missing values presidential vote shares
foreach var of varlist IMD5005_A-IMD5005_I {
replace `var'=.  if `var'<5
}


replace IMD5001_A=IMD5005_A if IMD5001_A==.&IMD5005_A!=.  // replace lower house scores with presidential scores where relevant
replace IMD5001_B=IMD5005_B if IMD5001_B==.&IMD5005_B!=.
replace IMD5001_C=IMD5005_C if IMD5001_C==.&IMD5005_C!=.
replace IMD5001_D=IMD5005_D if IMD5001_D==.&IMD5005_D!=.
replace IMD5001_E=IMD5005_E if IMD5001_E==.&IMD5005_E!=.
replace IMD5001_F=IMD5005_F if IMD5001_F==.&IMD5005_F!=.
replace IMD5001_G=IMD5005_G if IMD5001_G==.&IMD5005_G!=.
replace IMD5001_H=IMD5005_H if IMD5001_H==.&IMD5005_H!=.
replace IMD5001_I=IMD5005_I if IMD5001_I==.&IMD5005_I!=.


egen partynumber=rownonmiss(IMD3008_A-IMD3008_I) // how many like-dislike assigned
egen votenumber=rownonmiss(IMD5001_A-IMD5001_I) // how many parties' vote share is given 
gen completeA=(IMD3008_A!=.&IMD5001_A!=.) // if vote share and like-dislike score is given for party_A
gen completeB=(IMD3008_B!=.&IMD5001_B!=.)
gen completeC=(IMD3008_C!=.&IMD5001_C!=.)
gen completeD=(IMD3008_D!=.&IMD5001_D!=.)
gen completeE=(IMD3008_E!=.&IMD5001_E!=.)
gen completeF=(IMD3008_F!=.&IMD5001_F!=.)
gen completeG=(IMD3008_G!=.&IMD5001_H!=.)
gen completeH=(IMD3008_H!=.&IMD5001_G!=.)
gen completeI=(IMD3008_I!=.&IMD5001_I!=.)

egen completenumber=rowtotal(completeA-completeI) if votenumber!=0&partynumber!=0
replace completenumber=0 if partynumber==0
replace completenumber=0 if votenumber==0

*** Aff pol

egen meanlike=rowmean(IMD3008_A-IMD3008_I)

gen affpolA=(IMD3008_A-meanlike)^2
gen affpolB=(IMD3008_B-meanlike)^2
gen affpolC=(IMD3008_C-meanlike)^2 
gen affpolD=(IMD3008_D-meanlike)^2 
gen affpolE=(IMD3008_E-meanlike)^2 
gen affpolF=(IMD3008_F-meanlike)^2 
gen affpolG=(IMD3008_G-meanlike)^2 
gen affpolH=(IMD3008_H-meanlike)^2 
gen affpolI=(IMD3008_I-meanlike)^2 


egen sumaffpol=rowtotal(affpolA-affpolI) if partynumber!=0
gen affpol=sqrt(sumaffpol/partynumber)


***** WEIGHTED

*** Correct vote shares
egen sumvotes=rowtotal(IMD5001_A-IMD5001_I) if votenumber!=0

gen voteA=IMD5001_A/sumvotes 
gen voteB=IMD5001_B/sumvotes 
gen voteC=IMD5001_C/sumvotes 
gen voteD=IMD5001_D/sumvotes 
gen voteE=IMD5001_E/sumvotes 
gen voteF=IMD5001_F/sumvotes 
gen voteG=IMD5001_G/sumvotes 
gen voteH=IMD5001_H/sumvotes 
gen voteI=IMD5001_I/sumvotes 

*** check
egen allvotes=rowtotal(voteA-voteI)

gen helpA=voteA*IMD3008_A
gen helpB=voteB*IMD3008_B
gen helpC=voteC*IMD3008_C
gen helpD=voteD*IMD3008_D
gen helpE=voteE*IMD3008_E
gen helpF=voteF*IMD3008_F
gen helpG=voteG*IMD3008_G
gen helpH=voteH*IMD3008_H
gen helpI=voteI*IMD3008_I

egen weightedmeanlike=rowtotal(helpA-helpI)  if completenumber!=0

gen affpolAwgt=voteA*((IMD3008_A-weightedmeanlike)^2)
gen affpolBwgt=voteB*((IMD3008_B-weightedmeanlike)^2)
gen affpolCwgt=voteC*((IMD3008_C-weightedmeanlike)^2) 
gen affpolDwgt=voteD*((IMD3008_D-weightedmeanlike)^2)
gen affpolEwgt=voteE*((IMD3008_E-weightedmeanlike)^2)
gen affpolFwgt=voteF*((IMD3008_F-weightedmeanlike)^2)
gen affpolGwgt=voteG*((IMD3008_G-weightedmeanlike)^2)
gen affpolHwgt=voteH*((IMD3008_H-weightedmeanlike)^2)
gen affpolIwgt=voteI*((IMD3008_I-weightedmeanlike)^2)

egen affpolwgt=rowtotal(affpolAwgt-affpolIwgt) if completenumber!=0
replace affpolwgt=sqrt(affpolwgt)
replace affpolwgt=. if completenumber==1

*********

*out-party hostility-in-party like
egen minlike=rowmin(IMD3008_*)
egen maxlike=rowmax(IMD3008_*)

gen dummy=1 if minlike<5
replace dummy=0 if minlike>=5 & minlike!=.

*how many max liked and min liked
rename IMD3008_*? IMD3008_#, renumber

forval i=1/9 {
gen cluster_n`i'=1 if IMD3008_`i'==minlike & IMD3008_`i'!=. & minlike!=. & minlike<5
gen cluster_p`i'=1 if IMD3008_`i'==maxlike & IMD3008_`i'!=. & maxlike!=. & maxlike>5
}

egen numdislikes=rowtotal(cluster_n*) 
egen numlikes=rowtotal(cluster_p*)

*out party hostility
rename voteA vote1
rename voteB vote2
rename voteC vote3
rename voteD vote4
rename voteE vote5
rename voteF vote6
rename voteG vote7
rename voteH vote8
rename voteI vote9

forval i=1/9 {
gen out`i'=1 if IMD3008_`i'<5 & IMD3008_`i'!=. 
gen in`i'=1 if IMD3008_`i'>5 & IMD3008_`i'!=. 
gen clusterout`i'=out`i'*(5-IMD3008_`i')^2
gen clusterin`i'=in`i'*(IMD3008_`i'-5)^2
gen voteout`i'=clusterout`i'*vote`i'
gen votein`i'=clusterin`i'*vote`i'
}

egen numdislikes2=rowtotal(out1 out2 out3 out4 out5 out6 out7 out8 out9) 


egen outlike=rowtotal(voteout*)  if completenumber!=0 
replace outlike=. if  numlikes==partynumber |  numdislikes==partynumber 
replace outlike=sqrt(outlike)
egen inlike=rowtotal(votein*)  if completenumber!=0 
replace inlike=. if   numlikes==partynumber |  numdislikes==partynumber 
replace inlike=sqrt(inlike)

gen outpol=outlike-inlike

*descriptives
egen outpol_mean = mean(outpol), by(IMD1006_NAM)
egen afpol_mean = mean(affpolwgt), by(IMD1006_NAM)
egen me_out = mean(outlike), by(IMD1006_NAM)
egen me_in = mean(inlike), by(IMD1006_NAM)

gen diff9=me_in-me_out

graph dot me_out me_in  , over(IMD1006_NAM, sort(diff9)) xlabel() legend(pos(6)) legend(label(1 "Out-party Hostility") label(2 "In-party Like")) ysize(11) xsize(6.5) name(inout, replace)

*standardized for comparison
egen zoutpol=std(outpol)
egen zafpol=std(affpolwgt)

egen zout2 = mean(zoutpol), by(IMD1006_NAM)
egen zaf2 = mean(zafpol), by(IMD1006_NAM)

gen diff0=zaf2-zout2

graph dot zout2 zaf2  , over(IMD1006_NAM, sort(diff0)) xlabel() legend(pos(6)) legend(label(1 "Relative Hostility") label(2 "Affective Polarization")) ysize(11) xsize(6.5) name(rel_af, replace)

graph combine inout rel_af,  ysize(11) scale(1) col(2)

* By year
egen out_year = mean(outlike), by(IMD1008_YEAR)
egen in_year = mean(inlike), by(IMD1008_YEAR)

twoway (scatter out_year IMD1008_YEAR, mcolor(blue)) ///
       (lfit out_year IMD1008_YEAR, lcolor(blue) lwidth(thin)) ///
       (scatter in_year IMD1008_YEAR, mcolor(red)) ///
       (lfit in_year IMD1008_YEAR, lcolor(red) lwidth(thin)), ///
      legend(order(1 3) label(1 "Out-Party Hostility") label(3 "In-party Like") pos(6) row(2)) ///
       ytitle("Mean Values") xtitle("Year") name(inout_year, replace)
	   
egen rel_year = mean(zoutpol), by(IMD1008_YEAR)
egen afpol_year = mean(zafpol), by(IMD1008_YEAR)

twoway (scatter rel_year IMD1008_YEAR, mcolor(blue)) ///
       (lfit rel_year IMD1008_YEAR, lcolor(blue) lwidth(thin)) ///
       (scatter afpol_year IMD1008_YEAR, mcolor(red)) ///
       (lfit afpol_year IMD1008_YEAR, lcolor(red) lwidth(thin)), ///
	  legend(order(1 3) label(1 "Relative Hostility") label(3 "Affective Polarization") pos(6) row(2)) ///
       ytitle("Mean Values") xtitle("Year") name(relaf_year, replace)

	   graph combine inout_year relaf_year, scale(1) col(2)
	   
*controls
* Age
recode IMD2001_1 (9997/9999=.), gen(age)

*Gender
recode IMD2002 (2=1) (1=0) (3/9=.), gen(female)

*education
recode IMD2003 (6/9=.), gen(educ)

*self
recode IMD3006 (95/99=.), gen(self)

*demsat
recode IMD3010 (6=3) (7/9=.),  gen(diss_dem)

*turnout
recode IMD3001 (9999993/9999999=.), gen(turnout)  

*ppid
recode IMD3005_1 (7/9=.), gen(ppid)

*income
recode  IMD2006 (6/9=.), gen(income)

*WHO IS IN POWER CAN MAKE A DIFFERENCE
recode IMD3011 (7/9=.), gen(pdiff)

*who ppl vote make a difference
recode IMD3012 (7/9=.), gen(vdiff)

*overall
egen efficacy=rowmean(vdiff pdiff)

* Ideological extremity
recode IMD3006 (95/99=.), gen(idst)
by IMD1004, sort : egen double meanidst = mean(idst)
by IMD1004, sort : egen double sdidst = sd(idst)
replace idst=abs(idst-meanidst)/sdidst

*partisan loyal voting
recode IMD3005_3 ( 9999989/ 9999999=.)
recode IMD3002_LH_PL (9999988/9999999=.), gen(vchoice)
replace vchoice=2760002 if vchoice==2760001 & IMD1006_NAM=="Germany"
replace IMD3005_3=2760002 if IMD3005_3==2760001 & IMD1006_NAM=="Germany"
replace vchoice=IMD3002_PR_1 if IMD1006_NAM=="France" | IMD1006_NAM=="Kenya" | IMD1006_NAM=="Lithuania" | IMD1006_NAM=="Mexico" | IMD1006_NAM=="Philippines"    

replace vchoice=IMD3002_LH_DC if IMD1006_NAM=="Australia" | IMD1006_NAM=="Canada" | IMD1006_NAM=="Great Britain" | IMD1006_NAM=="Ireland"     


gen loyal=.
replace loyal=1 if vchoice==IMD3005_3 & vchoice!=.
replace loyal=0 if  turnout==1 &  loyal!=1 
replace loyal=0 if  turnout==0 
replace loyal=0 if  IMD3005_3!=. & loyal==.
replace loyal=0 if  vchoice!=. & loyal==.

*voted for the extremist party
recode IMD5012_A-IMD5012_I (97/99=.) // missing values expert left right
rename IMD5012_*? IMD5012_#, renumber

egen maxright=rowmax(IMD5012_*)
egen maxleft=rowmin(IMD5012_*)

gen radical=1 if (vchoice==IMD5000_A) & (maxleft==IMD5012_1 | maxright==IMD5012_1)
replace radical=1 if (vchoice==IMD5000_B) & (maxleft==IMD5012_2 | maxright==IMD5012_2)
replace radical=1 if (vchoice==IMD5000_C) & (maxleft==IMD5012_3 | maxright==IMD5012_3)
replace radical=1 if (vchoice==IMD5000_D) & (maxleft==IMD5012_4 | maxright==IMD5012_4)
replace radical=1 if (vchoice==IMD5000_E) & (maxleft==IMD5012_5 | maxright==IMD5012_5)
replace radical=1 if (vchoice==IMD5000_F) & (maxleft==IMD5012_6 | maxright==IMD5012_6)
replace radical=1 if (vchoice==IMD5000_G) & (maxleft==IMD5012_7 | maxright==IMD5012_7)
replace radical=1 if (vchoice==IMD5000_H) & (maxleft==IMD5012_8 | maxright==IMD5012_8)
replace radical=1 if (vchoice==IMD5000_I) & (maxleft==IMD5012_9 | maxright==IMD5012_9)
replace radical=0 if vchoice!=. & radical==. 


*RESULTS
pwcorr dummy outpol, sig
pwcorr affpolwgt outpol, sig
pwcorr affpolwgt outlike, sig

*
pwcorr zoutpol ppid, sig
pwcorr zafpol ppid, sig
pwcorr dummy ppid, sig

*party represents r's views
recode IMD3016_1 (7/9=.), gen(views)  

pwcorr zoutpol views, sig
pwcorr zafpol views, sig
pwcorr dummy views, sig


*DEM SAT
reg diss_dem zoutpol age female educ ppid income idst i.IMD1003
reg diss_dem zafpol age female educ ppid income idst i.IMD1003 if e(sample)
reg diss_dem dummy age female educ ppid income idst i.IMD1003 if e(sample)
estimates store dem1
reg diss_dem zafpol age female educ ppid income idst i.IMD1003 if e(sample)
estimates store dem2

reg diss_dem zoutpol age female educ ppid income idst i.IMD1003 if e(sample)
estimates store dem3
estat ic

coefplot dem1 dem2 dem3, keep(dummy zafpol zoutpol) title("Democratic Dissatisfaction") xline(0) ylabel(1 `" "Binary" "Hostility" "' 2 `" "Affective" "Polarization" "'    3  `" "Relative" "Hostility" "', angle(vertical)) legend(off) mcolor(blue) ciopts(lcolor(blue)) msize(medium)  lwidth(vthick) name(dem, replace)

*table
reg diss_dem zoutpol age female educ ppid income idst i.IMD1003
reg diss_dem zafpol age female educ ppid income idst i.IMD1003 if e(sample)
reg diss_dem dummy age female educ ppid income idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\dem.doc", keep(dummy age female educ ppid income idst) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) replace

reg diss_dem zafpol age female educ ppid income idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\dem.doc", keep(zafpol age female educ ppid income idst) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) append


reg diss_dem zoutpol age female educ ppid income idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\dem.doc", keep(zoutpol age female educ ppid income idst) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) append

**Vote for extreme party

logit radical zoutpol age educ income female ppid idst i.IMD1003 		
logit radical zafpol age educ income female ppid idst i.IMD1003 if e(sample) 		
logit radical dummy age educ income female ppid idst i.IMD1003 if e(sample)
estimates store rad1

logit radical zafpol age educ income female ppid idst i.IMD1003 if e(sample)
estimates store rad2

logit radical zoutpol age educ income female ppid idst i.IMD1003 if e(sample)
estimates store rad3

coefplot rad1 rad2 rad3, keep(dummy zafpol zoutpol) title("Extreme Party Voting") xline(0) ylabel(1 `" "Binary" "Hostility" "' 2 `" "Affective" "Polarization" "'    3  `" "Relative" "Hostility" "', angle(vertical)) legend(off) mcolor(blue) ciopts(lcolor(blue)) msize(medium)  lwidth(vthick) name(rad, replace)
		
		
graph combine dem rad,  scale(1) col(3)
		
*table
logit radical zoutpol age educ income female ppid idst i.IMD1003 		
logit radical zafpol age educ income female ppid idst i.IMD1003 if e(sample) 		
logit radical dummy age educ income female ppid idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\rad.doc", keep(dummy age educ income female ppid idst  ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  replace

logit radical zafpol age educ income female ppid idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\rad.doc", keep(zafpol age educ income female ppid idst  ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append

logit radical zoutpol age educ income female ppid idst i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\rad.doc", keep(zoutpol age educ income female ppid idst  ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append

*****	EFFICACY	
reg efficacy zoutpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003
reg efficacy zafpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
		reg efficacy dummy age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
estimates store ef1
		reg efficacy zafpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
estimates store ef2
		reg efficacy zoutpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
estimates store ef3

coefplot ef1 ef2 ef3, keep(dummy zafpol zoutpol) title("Political Efficacy") xline(0) ylabel(1 `" "Binary" "Hostility" "' 2 `" "Affective" "Polarization" "'    3  `" "Relative" "Hostility" "', angle(vertical)) legend(off) mcolor(blue) ciopts(lcolor(blue)) msize(medium)  lwidth(vthick) name(eff, replace)

*table
reg efficacy zoutpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003
reg efficacy zafpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
		reg efficacy dummy age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\eff.doc", keep(dummy age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) replace
		reg efficacy zafpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\eff.doc", keep(zafpol age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) append
		reg efficacy zoutpol age female educ ppid income idst diss_dem prev_turnout i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\eff.doc", keep(zoutpol age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addtext(Country-election FE, Yes) append


*Turnout
	logit turnout zoutpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003
	logit turnout zafpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
	logit turnout dummy age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
estimates store tur1
	logit turnout zafpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
estimates store tur2
logit turnout zoutpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
estimates store tur3

coefplot tur1 tur2 tur3, keep(dummy zafpol zoutpol) title("Turnout") xline(0) ylabel(1 `" "Binary" "Hostility" "' 2 `" "Affective" "Polarization" "'    3  `" "Relative" "Hostility" "', angle(vertical)) legend(off) mcolor(blue) ciopts(lcolor(blue)) msize(medium)  lwidth(vthick) name(turn, replace)

*table
	logit turnout zoutpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003
	logit turnout zafpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
	logit turnout dummy age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\tur.doc", keep(dummy age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  replace
	logit turnout zafpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\tur.doc", keep(zafpol age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append
logit turnout zoutpol age female educ ppid income idst diss_dem prev_turnout  i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\tur.doc", keep(zoutpol age female educ ppid income idst diss_dem prev_turnout) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append



* LOYAL
	logit loyal zoutpol age female educ ppid income idst diss_dem   i.IMD1003
logit loyal zafpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
logit loyal dummy age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
estimates store loy1
logit loyal zafpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
estimates store loy2
logit loyal zoutpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
estimates store loy3

coefplot loy1 loy2 loy3, keep(dummy zafpol zoutpol) title("Partisan Loyal Voting") xline(0) ylabel(1 `" "Binary" "Hostility" "' 2 `" "Affective" "Polarization" "'    3  `" "Relative" "Hostility" "', angle(vertical)) legend(off) mcolor(blue) ciopts(lcolor(blue)) msize(medium)  lwidth(vthick) name(loyal, replace)

		
graph combine eff turn loyal,   scale(1) col(3)


*table 
logit loyal zoutpol age female educ ppid income idst diss_dem   i.IMD1003
logit loyal zafpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
logit loyal dummy age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\loy.doc", keep(dummy age female educ ppid income idst diss_dem ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  replace
logit loyal zafpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\loy.doc", keep(zafpol age female educ ppid income idst diss_dem ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append
logit loyal zoutpol age female educ ppid income idst diss_dem   i.IMD1003 if e(sample)
outreg2 using "C:\Users\melek\Desktop\PHD\Paper 1_measurement paper\revision-data analysis\loy.doc", keep(zoutpol age female educ ppid income idst diss_dem ) dec(2) alpha(0.001, 0.01, 0.05)  coefastr se addstat(Log  likelihood, e(ll)) addtext(Country-election FE, Yes)  append


